﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		TrackBack.Builder.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion
 
using System;
using Topics.Radical.Validation;

namespace Dexter.Domain.Model {
	public partial class TrackBack {
		/// <summary>
		/// Creates a new instance of <see cref="TrackBack"/>.
		/// </summary>
		/// <param name="item">The item of the trackback.</param>
		/// <param name="website">The website of the trackback.</param>
		/// <param name="title">The title of the trackback.</param>
		/// <returns>
		/// A new instance of <see cref="TrackBack"/>
		/// </returns>
		/// <exception cref="ArgumentNullException"> If <paramref name="item"/> is <c>null</c>.</exception>
		/// <exception cref="ArgumentNullException"> If <paramref name="website"/> is <c>null</c>.</exception>
		/// <exception cref="ArgumentOutOfRangeException"> If <paramref name="item.Id"/> is not greater then 1.</exception>
		/// <exception cref="ArgumentOutOfRangeException"> If <paramref name="title"/> is <c>empty</c>.</exception>
		public static TrackBack CreateNewTrackback ( Item item , Uri website , string title ) {
			Ensure.That ( item )
				.Named ( "item" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotNull ( )
				.WithMessage ( "Invalid item." );

			Ensure.That ( item.Id )
				.Named ( "item.Id" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsGreaterThen ( 0 )
				.WithMessage ( "Invalid item id." );

			Ensure.That ( website )
				.Named ( "website" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotNull ( )
				.WithMessage ( "Invalid website uri." );

			Ensure.That ( title )
				.Named ( "title" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotNullNorEmpty ( )
				.WithMessage ( "Invalid trackback title." );

			return new TrackBack ( item , website , title );
		}
	}
}
